using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace SimpleFramework
{
    public static class UnityComponent_Extension
    {
        public static T GetComponent<T>(this Component target, string path) where T : Component
        {
            var child = target.transform.Find(path);
            if (child)
            {
                return child.GetComponent<T>();
            }
            return default(T);
        }

        public static Object GetComponent(this Component target, System.Type type, string path)
        {
            var child = target.transform.Find(path);
            if (child)
            {
                return child.GetComponent(type);
            }
            return null;
        }

        public static T GetComponent<T>(this GameObject target, string path) where T : Component
        {
            var child = target.transform.Find(path);
            if (child)
            {
                return child.GetComponent<T>();
            }
            return default(T);
        }

        public static Object GetComponent(this GameObject target, System.Type type, string path)
        {
            var child = target.transform.Find(path);
            if (child)
            {
                return child.GetComponent(type);
            }
            return null;
        }
    }
}
